package com.atguigu.ssyx.acl.service.impl;

import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * Created on 2023/6/30
 */
@Component
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    //条件分页查询，根据用户名查询分页信息
    @Override
    public IPage<Admin> selectPageUserList(Page<Admin> pageParam, AdminQueryVo adminQueryVo) {

        //查询用户名
        String userName = adminQueryVo.getUsername();
        String realName = adminQueryVo.getName();

        //构建MP查询条件
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();


        if(!StringUtils.isEmpty(userName)){
            wrapper.like(Admin::getUsername,userName);
        }

        if(!StringUtils.isEmpty(realName)){
            wrapper.like(Admin::getName,realName);
        }

        Page<Admin> adminPage = baseMapper.selectPage(pageParam, wrapper);

        return adminPage;
    }

}
